package com.example.tutorial.java.concurrent.limit;

import com.google.common.util.concurrent.RateLimiter;

import java.time.LocalTime;

/**
 * 令牌桶
 *
 * @author: cph
 * @date: 2022/8/16 15:18
 */
public class RateLimiterTokenBucket {

    public static void main(String[] args) throws InterruptedException {
        RateLimiter rateLimiter = RateLimiter.create(2);
        for (int i = 0; i < 10; i++) {
            LocalTime time = LocalTime.now();
            System.out.println(time + ": " + rateLimiter.tryAcquire());
            Thread.sleep(250);
        }

    }

}
